<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>示例</title>
</head>
<style>
    textarea{width: 500px;height: 300px;}
</style>
<body>
<div>
    <textarea id="textarea"></textarea>
    <button id="query_btn">查詢</button>
</div>
<script src="../js/jq/jquery-1.8.3.min.js"></script>
<script>
    $(document).ready(function () {
        let obj = {
            "query_arr":[],
            trim: function (str) {
                return str.replace(/(^\s*)|(\s*$)/g, "");
            },
            replaceStr:function (str,str1,str2) {
                return str.replace(str1,str2);
            }

        };

        $("#query_btn").bind("click",function () {
            obj.query_arr.length = 0;
            let tmp = [];
            let arr = [];
            let text = $("#textarea").val();
            tmp = text.split("\n");
            for (i in tmp){
                let arr_tpm = tmp[i].split(" ");
                for (j in arr_tpm){
                    if(arr_tpm[j] == ""){
                        continue;
                    }
                    arr.push(arr_tpm[j])
                }
            }
            tmp.length = 0;
            for (i in arr){
                let str = obj.replaceStr(arr[i],"，",",")
                let tmp_arr = str.split(",");
                for (j in tmp_arr){
                    if(tmp_arr[j] == ""){
                        continue;
                    }
                    obj.query_arr.push(tmp_arr[j])
                }
            }
            console.log(obj.query_arr)
        });
    });
</script>
</body>
</html>